$(document).ready(function() {
    function p(s) {
        return s < 10 ? '0' + s: s;
    };
    var option_text = $('#test').find("option:selected").text();
    var option_val = $('#test').find("option:selected").val();
    var myDate = new Date();
    var year=myDate.getFullYear();
    var month=myDate.getMonth()+1;
    var date = myDate.getDate();
    var start = year + '-' + p(month) + '-' + p(date)
    $('#start').val(start);
    $('#end').val(start);
    var jqxhr = jQuery.ajax({
        url: '/',
        type: 'POST',
        data: {
            start: start,
            end: start,
            option_val: option_val
        },
        dataType: 'json',
        success: function(data) {
            // var datas = data[]
            // window.location.reload();
        },
        error:function(data){
            alert(888);
        }
    });

    jqxhr.done(
        function (data) {
            var datas = $.parseJSON(data.data)
            if ($.isEmptyObject(datas)) {
                var tmp1 = '<h1><marquee direction=right>暂无数据！</marquee></h1>';
                $("#container_line").html(tmp1);
                return;
            }
            $('#container_line').highcharts({
                chart: {
                    type: 'line'
                },
                title: {
                    text: option_text
                },
                subtitle: {
                    text: '数据来源: MySQL数据库搜索'
                },
                xAxis: {
                    categories: datas[0]
                },
                yAxis: {
                    title: {
                        text: '总数(个)'
                    }
                },
                plotOptions: {
                    line: {
                        dataLabels: {
                            enabled: true          // 开启数据标签
                        },
                        enableMouseTracking: false // 关闭鼠标跟踪，对应的提示框、点击事件会失效
                    }
                },
                series: datas[1]
            });
        }
    )
    $('#search').click(function() {
        var start = $('#start').val();
        var end = $('#end').val();
        var option_text = $('#test').find("option:selected").text();
        var option_val = $('#test').val();
        var jqxhr = jQuery.ajax({
            url: '/',
            type: 'POST',
            data: {
                start: start,
                end: end,
                option_val: option_val
            },
            dataType: 'json',
            success: function(data) {
                // var datas = data[]
                // alert(data.data);
                // window.location.reload();
            },
            error:function(data){
                alert(888);
            }
            });
        jqxhr.done(
            function (data) {
                var datas = $.parseJSON(data.data)
                if ($.isEmptyObject(datas)) {
                    var tmp1 = '<h1><marquee direction=right>暂无数据！</marquee></h1>';
                    $("#container_line").html(tmp1);
                    return;
                }
                $('#container_line').highcharts({
                    chart: {
                        type: 'line'
                    },
                    title: {
                        text: option_text
                    },
                    subtitle: {
                        text: '数据来源: MySQL数据库搜索'
                    },
                    xAxis: {
                        categories: datas[0]
                    },
                    yAxis: {
                        title: {
                            text: '总数(个)'
                        }
                    },
                    plotOptions: {
                        line: {
                            dataLabels: {
                                enabled: true          // 开启数据标签
                            },
                            enableMouseTracking: false // 关闭鼠标跟踪，对应的提示框、点击事件会失效
                        }
                    },
                    series: datas[1]
                });
            }
            )
    });
});